package com.emellend.api.progressbar;

import com.emellend.api.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ProgressBar;
/**
 * getSecondaryProgress的使用。可以实现缓冲效果
 * @author tiangh
 *
 */
public class ProgressBar1 extends Activity implements OnClickListener{
	
	private ProgressBar mProgressHorizontal;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_PROGRESS);
		setContentView(R.layout.progressbar_1);
		setProgressBarVisibility(true);
		mProgressHorizontal = (ProgressBar) this.findViewById(R.id.progress_horizontal);
		setProgress(mProgressHorizontal.getProgress()*100);
		setSecondaryProgress(mProgressHorizontal.getSecondaryProgress()*100);
		addListener();
	}

	private void addListener() {
		this.findViewById(R.id.decrease).setOnClickListener(this);
		this.findViewById(R.id.decrease_secondary).setOnClickListener(this);
		this.findViewById(R.id.increase).setOnClickListener(this);
		this.findViewById(R.id.increase_secondary).setOnClickListener(this);
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.decrease:
			mProgressHorizontal.incrementProgressBy(-1);
			setProgress(mProgressHorizontal.getProgress()*100);
			break;
		case R.id.decrease_secondary:
			mProgressHorizontal.incrementSecondaryProgressBy(-1);
			setSecondaryProgress(mProgressHorizontal.getSecondaryProgress()*100);
			break;
		case R.id.increase:
			mProgressHorizontal.incrementProgressBy(1);
			setProgress(mProgressHorizontal.getProgress()*100);
			break;
		case R.id.increase_secondary:
			mProgressHorizontal.incrementSecondaryProgressBy(1);
			setSecondaryProgress(mProgressHorizontal.getSecondaryProgress()*100);
			break;
		}
	}
	
	
}
